﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using DTO_MechSys;

namespace FORMS_MechSys
{
    public partial class frmSplashScreen : Form
    {


        public frmSplashScreen()
        {
            InitializeComponent();
            tlpPrincipal.RowStyles[4].Height = (float)(0);
            this.Size = new Size(520, 160);
            try
            {
                pictureBox30.BackColor = pictureBox21.BackColor = pictureBox22.BackColor = pictureBox23.BackColor =
                    pictureBox10.BackColor = pictureBox11.BackColor = pictureBox12.BackColor = pictureBox13.BackColor =
                    pictureBox17.BackColor = pictureBox16.BackColor = pictureBox15.BackColor = pictureBox14.BackColor =
                    pictureBox27.BackColor = pictureBox26.BackColor = pictureBox25.BackColor = pictureBox24.BackColor =
                    pictureBox18.BackColor = pictureBox19.BackColor = pictureBox20.BackColor = pictureBox1.BackColor =
                    pictureBox28.BackColor = pictureBox29.BackColor = pictureBox31.BackColor = pictureBox32.BackColor =
                    pictureBox9.BackColor = pictureBox6.BackColor = pictureBox5.BackColor = pictureBox2.BackColor =
                    pictureBox8.BackColor = pictureBox7.BackColor = pictureBox4.BackColor = pictureBox3.BackColor =
                    pictureBox33.BackColor = pictureBox34.BackColor = btnEntrar.BackColor =
                    tlpAutenticacao.BackColor =
                    new BLL_MechSys.BLLCor().Buscar("Principal").Cor;
                label2.ForeColor = label3.ForeColor =
                btnEntrar.ForeColor = new BLL_MechSys.BLLCor().Buscar("Letra").Cor;
                this.tableLayoutPanel1.BackColor = this.BackColor = new BLL_MechSys.BLLCor().Buscar("Fundo").Cor;

            }
            catch (Exception)
            {
                new frmMessageBox().Show("O sistema não pode ser aberto.\n\nContate a equipe de Desenvolvimento", "Erro de comunicação com o Banco de Dados");
                Environment.Exit(0);
            }
        }

        public void Carregando()
        {
            if (!pictureBox1.Visible)
                pictureBox1.Visible = true;
            else if (!pictureBox2.Visible)
                pictureBox2.Visible = true;
            else if (!pictureBox3.Visible)
                pictureBox3.Visible = true;
            else if (!pictureBox4.Visible)
                pictureBox4.Visible = true;
            else if (!pictureBox5.Visible)
                pictureBox5.Visible = true;
            else if (!pictureBox6.Visible)
            {
                label1.Text = "Conexão Pronta...";
                pictureBox6.Visible = true;
            }
            else if (!pictureBox7.Visible)
                pictureBox7.Visible = true;
            else if (!pictureBox8.Visible)
                pictureBox8.Visible = true;
            else if (!pictureBox9.Visible)
                pictureBox9.Visible = true;
            else if (!pictureBox10.Visible)
            {
                label1.Text = "Iniciando MechSys...";
                pictureBox10.Visible = true;
            }
            else if (!pictureBox11.Visible)
                pictureBox11.Visible = true;
            else if (!pictureBox12.Visible)
                pictureBox12.Visible = true;
            else if (!pictureBox13.Visible)
                pictureBox13.Visible = true;
            else if (!pictureBox14.Visible)
                pictureBox14.Visible = true;
            else if (!pictureBox15.Visible)
                pictureBox15.Visible = true;
            else if (!pictureBox16.Visible)
            {
                label1.Text = "Faça Login.";

                pictureBox16.Visible = true;
            }
            else if (!pictureBox17.Visible)
                pictureBox17.Visible = true;
            else if (!pictureBox18.Visible)
                pictureBox18.Visible = true;
            else if (!pictureBox19.Visible)
                pictureBox19.Visible = true;
            else if (!pictureBox20.Visible)
                pictureBox20.Visible = true;
        }

        public void ExibirLogin()
        {
            tlpAutenticacao.Enabled = true;
            tlpLoginFull.Visible = true;

            txtUsuario.Focus();
            tlpPrincipal.RowStyles[3].Height = (float)(0);
            tlpPrincipal.RowStyles[2].Height = (float)(0);
            tlpPrincipal.RowStyles[4].Height = (float)(110);
            this.Size = new Size(520, 220);
        }

        private void txtUsuario_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape && string.IsNullOrWhiteSpace(BLL_MechSys.BLLUtilitarios.FuncionarioLogado))
                Environment.Exit(0);
            else if (e.KeyCode == Keys.Enter)
                btnEntrar_Click(null, null);
        }

        private void txtSenha_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape && string.IsNullOrWhiteSpace(BLL_MechSys.BLLUtilitarios.FuncionarioLogado))
                Environment.Exit(0);
            else if (e.KeyCode == Keys.Enter)
                btnEntrar_Click(null, null);
        }

        private void btnEntrar_Click(object sender, EventArgs e)
        {
            if (new BLL_MechSys.BLLUsuario().Autenticar(txtUsuario.Text, txtSenha.Text))
            {

                BLL_MechSys.BLLUtilitarios.FuncionarioLogado = new BLL_MechSys.BLLUsuario().FuncionarioLogado();
                BLL_MechSys.BLLUtilitarios.FuncionarioLogadoID = new BLL_MechSys.BLLUsuario().FuncionarioLogadoID();

                pictureBox30.BackColor = pictureBox21.BackColor = pictureBox22.BackColor = pictureBox23.BackColor =
                    pictureBox10.BackColor = pictureBox11.BackColor = pictureBox12.BackColor = pictureBox13.BackColor =
                    pictureBox17.BackColor = pictureBox16.BackColor = pictureBox15.BackColor = pictureBox14.BackColor =
                    pictureBox27.BackColor = pictureBox26.BackColor = pictureBox25.BackColor = pictureBox24.BackColor =
                    pictureBox18.BackColor = pictureBox19.BackColor = pictureBox20.BackColor = pictureBox1.BackColor =
                    pictureBox28.BackColor = pictureBox29.BackColor = pictureBox31.BackColor = pictureBox32.BackColor =
                    pictureBox9.BackColor = pictureBox6.BackColor = pictureBox5.BackColor = pictureBox2.BackColor =
                    pictureBox8.BackColor = pictureBox7.BackColor = pictureBox4.BackColor = pictureBox3.BackColor =
                    pictureBox33.BackColor = pictureBox34.BackColor = btnEntrar.BackColor =
                    tlpAutenticacao.BackColor =
                    new BLL_MechSys.BLLCor().Buscar("Principal").Cor;
                label2.ForeColor = label3.ForeColor =
                btnEntrar.ForeColor = new BLL_MechSys.BLLCor().Buscar("Letra").Cor;
                this.tableLayoutPanel1.BackColor = this.BackColor = new BLL_MechSys.BLLCor().Buscar("Fundo").Cor;


                tlpAutenticacao.Visible = false;
                tlpAutenticacao.Enabled = false;
                IniciarSessao();
                tlpLoginFull.Visible = false;
                this.Close();
            }
            else
            {
                new frmMessageBox().Show("Usuário ou senha incorretos.", "MechSys", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void IniciarSessao()
        {
            pictureBox1.Visible = pictureBox10.Visible = pictureBox11.Visible = pictureBox2.Visible =
                pictureBox12.Visible = pictureBox13.Visible = pictureBox14.Visible = pictureBox15.Visible =
                pictureBox16.Visible = pictureBox17.Visible = pictureBox18.Visible = pictureBox19.Visible =
                pictureBox20.Visible = pictureBox3.Visible = pictureBox4.Visible = pictureBox5.Visible =
                pictureBox6.Visible = pictureBox7.Visible = pictureBox8.Visible = pictureBox9.Visible = false;

            tlpPrincipal.RowStyles[4].Height = (float)(0);
            tlpPrincipal.RowStyles[3].Height = (float)(30);
            tlpPrincipal.RowStyles[2].Height = (float)(20);
            this.Size = new Size(520, 160);

            label1.Text = "Iniciando Sessão...";
            Thread.Sleep(60);
            pictureBox1.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox2.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox3.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox4.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox5.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox6.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox7.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox8.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox9.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox10.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox11.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox12.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox13.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox14.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox15.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox16.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox17.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox18.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox19.Visible = true;
            Application.DoEvents();
            Thread.Sleep(60);
            pictureBox20.Visible = true;
            Application.DoEvents();
            Thread.Sleep(160);


        }

        private void pictureBox35_MouseDown(object sender, MouseEventArgs e)
        {
            txtSenha.UseSystemPasswordChar = false;
            Application.DoEvents();
        }

        private void pictureBox35_MouseUp(object sender, MouseEventArgs e)
        {
            txtSenha.UseSystemPasswordChar = true;
            Application.DoEvents();

        }
    }
}
